package com.hjm.ui.goods;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hjm.ui.R;

public class GoodsComment extends LinearLayout {
    private TextView pjNumTextView, pjUserNameTextView, pjContentTextView, pjTimeTextView, pjTypeTextView;
    private ImageView pjUserImgView;
    public GoodsComment(Context context) {
        super(context);
        init();
    }

    public GoodsComment(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GoodsComment);
        String contentNum = a.getString(R.styleable.GoodsComment_pjNumText);
        Drawable drawable = a.getDrawable(R.styleable.GoodsComment_pjUserImg);
        String userNameText = a.getString(R.styleable.GoodsComment_pjUserNameText);
        String contentText = a.getString(R.styleable.GoodsComment_pjContentText);
        String timeText = a.getString(R.styleable.GoodsComment_pjTimeText);
        String typeText = a.getString(R.styleable.GoodsComment_pjTypeText);
        if(contentNum != null){
            pjNumTextView.setText("宝贝评价("+contentNum+")");
        }
        if(drawable != null){
            pjUserImgView.setImageDrawable(drawable);
        }
        if(userNameText != null){
            pjUserNameTextView.setText(userNameText);
        }
        if(contentText != null){
            pjContentTextView.setText(contentText);
        }
        if(timeText != null){
            pjTimeTextView.setText(timeText);
        }
    }

    public GoodsComment(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    private void init() {
        // 在这里添加你的布局和逻辑
        LayoutInflater.from(getContext()).inflate(R.layout.layout_goods_comment, this, true);
        pjNumTextView = findViewById(R.id.text_view_pj_num);
        pjUserImgView = findViewById(R.id.image_view_pj_user_img);
        pjUserNameTextView = findViewById(R.id.text_view_pj_user_name);
        pjContentTextView = findViewById(R.id.text_view_pj_content);
        pjTimeTextView = findViewById(R.id.text_view_pj_time);
        pjTypeTextView = findViewById(R.id.text_view_pj_select_type);
    }
}
